#include "rgb_to_mp4_window.h"
#include <QDebug>
#include <QFileDialog>
#include <qmessagebox.h>
#include "rgb2mp4thread.h"

rgb_to_mp4_window::rgb_to_mp4_window(QWidget* parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	this->setWindowTitle("RGB转MP4");
}
void rgb_to_mp4_window::choiceRGBFile()
{
	// 设置文件过滤器，仅允许选择 .rgb 文件
	QString filter = "RGB 文件 (*.*);;所有文件 (*.*)";
	// 打开文件选择对话框，选择单个文件
	QString filePath = QFileDialog::getOpenFileName(this, "选择 RGB 文件", "E:\\BaiduNetdiskDownload\\test_resource", filter);
	this->inFilePath = filePath;
	this->ui.rgbEditPath->setText(filePath);
	qDebug() << "选择rgb文件";

}
void rgb_to_mp4_window::choiceMP4OutPath()
{
	// 打开文件夹选择对话框
	QString directoryPath = QFileDialog::getSaveFileName(nullptr, "保存文件", "E:\\BaiduNetdiskDownload\\test_resource", "媒体文件(*.*)");

	if (!directoryPath.isEmpty()) {
		qDebug() << "选择的文件夹路径: " << directoryPath;
	}
	else {
		qDebug() << "未选择文件夹";
	}
	this->ui.mp4EditPath->setText(directoryPath);
	this->outFilePath = directoryPath;
}

void rgb_to_mp4_window::rgbToMP4Func()
{
	qDebug() << "开始转换";
	if (this->inFilePath.isEmpty() || this->outFilePath.isEmpty()) {
		QMessageBox::warning(this, "温馨提示", "输入、输出文件的路径不能为空");
	}
	//const char* inFile = this->inFilePath.toStdString().c_str();
	//qDebug() << inFile;
	//const char* outFile = this->inFilePath.toStdString().c_str();
	//qDebug() << inFile;
	char inFile[100];
	char outFile[100];
	qstrncpy(inFile, this->inFilePath.toStdString().c_str(), this->inFilePath.length()+1);
	qstrncpy(outFile, this->outFilePath.toStdString().c_str(), this->outFilePath.length()+1);
	qDebug() <<"输入路径:" << inFile;
	qDebug() <<"输出路径：" << outFile;
	RGB2MP4Thread::Get()->inFile = inFilePath;
	RGB2MP4Thread::Get()->outFile = outFilePath;
	RGB2MP4Thread::Get()->width = ui.videoWidthEdit->text().toInt();;
	RGB2MP4Thread::Get()->height = ui.videoHeightEdit->text().toInt();
	RGB2MP4Thread::Get()->fps = ui.fpsEdit->text().toInt();
	RGB2MP4Thread::Get()->Start();

}

rgb_to_mp4_window::~rgb_to_mp4_window()
{

}
